﻿<%@ Page Language="VB" AutoEventWireup="false" CodeFile="mtUsersFCListPopup.aspx.vb" Inherits="mtUsersFCListPopup" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %>

<%@ Register Assembly="ISNet.WebUI.ISDataSource, Version=1.0.1500.1, Culture=neutral, PublicKeyToken=c4184ef0d326354b"
    Namespace="ISNet.WebUI.DataSource" TagPrefix="ISDataSource" %>
<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>

        function WebGrid1_OnEditKeyDown(controlId) {
            //alert(event.keyCode);
            var grid = ISGetObject("WebGrid1");

            var totalRows = grid.TotalRows;
            var totalCells = grid.TotalCells;
            var curRow = grid.GetSelectedObject().rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;

            // if enter key
            if (event.keyCode == 13) {
                return false;
                //var ar = grid.getActiveRow();
                //if (ar.IsAddNewRow) {
                //    ar.commit();
                //}
                //else {
                //    event.keyCode = 40;
                //    keyDown(curRow, curRow + 1, curCell - 1);
                //}
            }

                // if up arrow
            else if (event.keyCode == 38) {
                if (totalRows >= 2) {
                    if (curRow > 0) {
                        keyDown(curRow, curRow - 1, curCell - 1);
                    }
                }
            }

                // if down arrow key
            else if (event.keyCode == 40) {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
            }
                // if left arrow key
            else if (event.keyCode == 37) {
                if (curCell > 0) {
                    //jq(document).trigger(jq.Event('keydown', { keyCode: 9, shiftKey: true }));
                    //var press = jQuery.Event("keydown");
                    //press.shiftKey = false;
                    //press.which = 9;
                    //jq("WebGrid1").trigger(press);
                    //alert("x");
                    //return;
                    keyDown2(curRow, curRow, curCell - 2);
                }
            }
                // if right arrow key
            else if (event.keyCode == 39) {
                //if (curCell < totalCells - 1) {
                event.keyCode = 9;
                //}
            }


        }
        function keyDown(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.SetFocus();
            cell2.Select(true);
            nextRowEl.Select();
            cell1.ActivateEdit();
        }
        function keyDown2(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.SetFocus();
            cell1.Select(true);
            nextRowEl.Select();
            cell1.ActivateEdit();

        }

        function triggerKeyEvents(field, keyCode, shiftKey, ctrlKey) {

            field = $(field);

            shiftKey = Boolean(shiftKey);

            ctrlKey = Boolean(ctrlKey);


            field.simulate("keydown", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

            field.simulate("keypress", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });


            if (field.is(HTML5_TEXT_INPUT_FIELD_SELECTOR)) {

                applyKeyCodeToValue(field, keyCode);

            }


            field.simulate("keyup", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

        }

        function SaveScrollPosition(gridId, action) {
            // collecting the last position
            // of the vertical scrollbar
            // by obtaining the scrollTop property
            var grid = ISGetObject(gridId);
            // obtain the scrollTop and scrollLeft property 
            // of the vertical scrollbar and horizontal scrollbar
            var vl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop + "";
            var hl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft + "";
            // only send the scrollTop property
            // of the server if the action performed
            // by the grid OTFPB is 'Refresh'

            //if (action == "Refresh") {
            // sending over the scrollTop and scrollLeft property
            // to the server by using AddInput method
            grid.AddInput("scrollTopPos", vl);
            grid.AddInput("scrollLeftPos", hl);
            //}

            return true;
        }
        function ApplyLatestScroll(gridId, y, x) {
            // set back the previous scrollTop and scrollLeft property or
            // vertical and horizontal scroll position with 
            // the parameter sent from the server side
            var grid = ISGetObject(gridId);
            // manually configure the vertical and horizontal scroll position
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop = y;
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft = x;

            var cellEl = grid.GetActiveEditCell().ToCellObject();
            grid.SetFocus();
            cellEl.ActivateEdit();
            return true;
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div style="margin-left: 10px;">
            <asp:Label ID="L_FundCenter" runat="server" Text="Label"></asp:Label>
          <%--  <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                CellPadding="1" ForeColor="#333333" Width="300px">
                <Columns>
                    <asp:TemplateField HeaderText="Fund Center">
                        <ItemTemplate>
                            <asp:Label ID="ID" runat="server" Text='<%# Bind("FundCenterCode")%>'></asp:Label>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Left" />
                        <HeaderStyle Font-Bold="False" ForeColor="White" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Description">
                        <ItemTemplate>
                            <asp:Label ID="ID" runat="server" Text='<%# Bind("Description")%>'></asp:Label>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Left" />
                        <HeaderStyle Font-Bold="False" ForeColor="White" />
                    </asp:TemplateField>
                </Columns>
                <RowStyle BackColor="#EFF3FB" />
                <EditRowStyle BackColor="Gainsboro" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" Font-Bold="True"
                    Font-Underline="True" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Underline="False" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
                <PagerSettings Mode="NumericFirstLast" />
            </asp:GridView>--%>

             <ISWebGrid:WebGrid ID="WebGrid1" runat="server" UseDefaultStyle="True" Width="325px" DefaultStyleMode="Silver" Height="330px" OnInitializeRow="WebGrid1_InitializeRow">
                <LayoutSettings AllowAddNew="No" EditOnClick="false" AllowColumnMove="No"
                    AllowEdit="No" AllowDelete="No" AllowSorting="Yes" ColumnFooters="Yes" NewRowLostFocusAction="AlwaysUpdate"
                    ResetNewRowValuesOnError="False" InProgressUIBehavior="ChangeCursorToHourGlass"
                    AlwaysShowHelpButton="false" PagingMode="ClassicPaging" PagingSize="10" ColumnFooterAggregateMode="CalculateAllData"
                    VirtualLoadMode="LargeData" AllowGrouping="Yes" VirtualPageSize="10">
                    <RowStyle Font-Names="Tahoma" Font-Size="9" CustomRules="overflow: hidden;" />
                    <AlternatingRowStyle Font-Names="Tahoma" Font-Size="9" BackColor="#fbfbfb" CustomRules="overflow: hidden;" />
                    <ClientSideEvents OnRowContextMenu="WebGrid1_OnRowContextMenu" OnEditKeyDown="WebGrid1_OnEditKeyDown" />
                </LayoutSettings>
                <RootTable DataKeyField="Id" NewRowInfoText="เพิ่มรายการ">
                    <Columns>
                        <ISWebGrid:WebGridColumn Caption="FundCenterCode" DataMember="FundCenterCode" Name="FundCenterCode" Width="100" TextboxMaxlength="4">
                            <HeaderStyle HorizontalAlign="Center" />
                            <CellStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="Description" DataMember="Description" Name="Description" Width="200">
                            <HeaderStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                    </Columns>
                </RootTable>
            </ISWebGrid:WebGrid>
        </div>
        <%=ScriptText %>
    </form>
</body>

</html>
